import sqlite3
import os

# 获取当前脚本所在目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建数据库路径，向上两级目录
db_path = os.path.join(current_dir, '../../trade_monitor.db')

symbol = "SHFE.ni2506"
stop_loss_limit = 300

try:
    conn = sqlite3.connect(db_path)  # 修正为使用构建好的 db_path
    cursor = conn.cursor()
    cursor.execute("SELECT limit_stoploss FROM products WHERE exchange_code=? AND is_monitored=1", (symbol,))
    result = cursor.fetchone()
    print(result)
    conn.close()
    if result is not None:
        stop_loss_limit = result[0] 
    print(stop_loss_limit)           
except Exception as e:
    print(f"从数据库获取 {symbol} 止损限额时出错: {e}")


# print(stop_loss_limit)
